#include "ResultResponse.h"

namespace Softwarer
{
	ResultResponse::ResultResponse()
	{

	}

	ResultResponse::ResultResponse(const QByteArray& bytes)
		: m_jsonObject(createJsonObject(bytes))
	{

	}
	QJsonObject ResultResponse::createJsonObject(const QByteArray& bytes)
	{
		QJsonDocument doc = QJsonDocument::fromJson(bytes);

		if (!doc.isObject()) 
		{
			return QJsonObject();
		}
		return doc.object();
	}
	bool ResultResponse::toBool(const QString& key)
	{
		if (m_jsonObject.contains(key))
		{
			m_jsonObject.value(key).toString();
			return m_jsonObject.value(key).toBool();
		}
		return false;
	}
	QString ResultResponse::toString(const QString& key) 
	{
		if (m_jsonObject.contains(key))
		{
			return m_jsonObject.value(key).toString();
		}
		return QString();
	}
}